//
//  ONSettingViewController.m
//  XProject
//
//  Created by Familly on 3/5/15.
//  Copyright (c) 2015 Familly. All rights reserved.
//

#import "ONSettingViewController.h"
#import "ONReportViewController.h"
#import "ONMessageViewController.h"
#import "ONSettingEntity.h"
@interface ONSettingViewController ()

@end

@implementation ONSettingViewController
+ (instancetype)sharedInstance {
    static id messageVCSharedInstance = nil;
    static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{
        messageVCSharedInstance = [[self alloc] initFromIB];
    });
    return messageVCSharedInstance;
}
- (IBAction)clickSwitchButton:(id)sender {
}
-(id)initFromIB{
    UIStoryboard *iPhoneStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    self = [iPhoneStoryboard instantiateViewControllerWithIdentifier:@"ONSettingViewController"];
    self.view.frame = APP_DELEGATE.window.bounds;
    // self.view.hidden = YES;
    [APP_DELEGATE.window addSubview:self.view];
    [APP_DELEGATE.window sendSubviewToBack:self.view];
    
    if (self) {
        
    }
    
    return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (IBAction)clickSwitch:(id)sender {
    isON=!isON;
    [[NSUserDefaults standardUserDefaults] setBool:isON forKey:@"EnableNotification"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
- (IBAction)messageClick:(id)sender {
    
    
    for (UIViewController *viewC in self.navigationController.viewControllers) {
        if ([viewC isKindOfClass:[ONMessageViewController class]]) {
            NSLog(@"-----------------");
            
            [self.navigationController popToViewController:viewC animated:NO];
            return;
        }
    }
    //[self.navigationController pushViewController:[ONMessageViewController sharedInstance] animated:false];
}
- (IBAction)reportClick:(id)sender {
    for (UIViewController *viewC in self.navigationController.viewControllers) {
        if ([viewC isKindOfClass:[ONReportViewController class]]) {
            //newOrderVC = (ONSettingViewController*)viewC;
            [self.navigationController popToViewController:viewC animated:NO];
            return;
        }
    }
    [self.navigationController pushViewController:[ONReportViewController sharedInstance] animated:false];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     [_lbSetting setTextColor:TEXT_TITLE_COLOR];
    [_lbNotification setTextColor:TEXT_TITLE_COLOR];
     [_lbBranch setTextColor:COLOR_OF_TEXT];
    [_lbBadWords setTextColor:COLOR_OF_TEXT];
    UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc]
                                      initWithTarget:self action:@selector(tap:)];
    [self.view addGestureRecognizer: tapRec];
    _textFieldBrach.delegate=self;
    _textView.delegate=self;
    ONSettingEntity *item =[ONGlobal getSettingEntity];
    isON=item.notification;
    [_switchButton setOn:isON];
    _textFieldBrach.text=item.brand;
    _textView.text=item.email;
    [[_textView layer] setBorderColor:[[UIColor grayColor] CGColor]];
    [[_textView layer] setBorderWidth:1.3];
    [[_textView layer] setCornerRadius:5];
    
}
-(void)dealloc
{
    _textFieldBrach.delegate=nil;
    _textView.delegate=nil;
}
/**
 * Should Return text Field   .
 */
-(BOOL)textViewShouldEndEditing:(UITextView *)textView
{
    [textView resignFirstResponder];
    return YES;
    
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [textField resignFirstResponder];
    return YES;
}
/**
 * Tap to Screen   .
 */
-(void)tap:(UITapGestureRecognizer *)tapRec{
    [[self view] endEditing: YES];
    [UIView animateWithDuration:0.28 animations:^{
        CGRect frame = self.view.frame;
        frame.origin.y = 0;
        self.view.frame = frame;
    }];
}

@end
